package com.own.component.mybatis.injector;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.own.component.mybatis.hook.CustomMybatisHook;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;

/**
 * CustomInjector
 *
 * @author chenxueli
 * @date 2020/9/17 11:02
 */
@Component
public class CustomInjector extends DefaultSqlInjector {

    @Resource
    private List<CustomMybatisHook> customMybatisHookList;

    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
        var methodList = super.getMethodList(mapperClass, tableInfo);
        customMybatisHookList.stream().sorted(Comparator.comparing(CustomMybatisHook::order)).forEach(hook -> {
            hook.run(methodList, mapperClass, tableInfo);
        });
        return methodList;
    }

}
